﻿using System.Linq;
using System.Web.Mvc;

using EPiServer.Personalization.VisitorGroups;

namespace EPiServer.Labs.MobilePack.Core
{
    public class BrowserModel : CriterionModelBase
    {
        [DojoWidget(SelectionFactoryType = typeof(DeviceSelectionFactory), AdditionalOptions = "{ selectOnClick: true }")]
        public string Device { get; set; }

        public override ICriterionModel Copy()
        {
            return base.ShallowCopy();
        }
    }

    public class DeviceSelectionFactory : ISelectionFactory
    {
        public System.Collections.Generic.IEnumerable<SelectListItem> GetSelectListItems(System.Type property)
        {
            return MobilePackSection.CurrentSection.Devices.Cast<DeviceElement>().Select(de => new SelectListItem() { Text = de.Name, Value = de.UserAgent });
        }
    }
}